package com.javalong.affairs.module.renwujinzhang.activity.progress;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.javalong.affairs.R;
import com.javalong.affairs.base.common.ViewHolder;
import com.javalong.affairs.base.constant.BundleKey;
import com.javalong.affairs.base.utils.TimeUtils;
import com.javalong.affairs.module.renwujinzhang.activity.RecycleListActivity;
import com.javalong.affairs.module.renwujinzhang.model.ProgressModel;

import java.io.Serializable;
import java.util.List;

/**
 * 阶段界面
 */
public class ProgressActivity extends RecycleListActivity {

    private List<List<ProgressModel>> progressModels;

    public static void toThisActivity(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, ProgressActivity.class);
        context.startActivity(intent);
    }

    public static void toThisActivity(Context context, List<List<ProgressModel>> progressModelList) {
        Intent intent = new Intent();
        intent.setClass(context, ProgressActivity.class);
        intent.putExtra(BundleKey.PROGRESSLIST, (Serializable) progressModelList);
        context.startActivity(intent);
    }

    @Override
    public void afterInit() {
        getSupportActionBar().setTitle("任务进度列表");
        progressModels = (List<List<ProgressModel>>) getIntent().getSerializableExtra(BundleKey.PROGRESSLIST);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_task_progress, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        LinearLayout ll_root = holder.getView(R.id.ll_root);
        TextView tv_title = holder.getView(R.id.tv_title);
        TextView tv_content = holder.getView(R.id.tv_content);
        TextView tv_starttime = holder.getView(R.id.tv_starttime);
        TextView tv_endtime = holder.getView(R.id.tv_endtime);
        TextView tv_sender = holder.getView(R.id.tv_sender);
        TextView tv_main = holder.getView(R.id.tv_main);
        final List<ProgressModel> progressModelList = progressModels.get(position);
        ProgressModel progressModel = progressModelList.get(0);
        if (progressModel == null) {
            return;
        }
        tv_title.setText(progressModel.getTitle());
        tv_content.setText(progressModel.getContent());
        tv_starttime.setText(TimeUtils.getFormatTime2(progressModel.getTimeBegin()));
        tv_endtime.setText(TimeUtils.getFormatTime2(progressModel.getTimeEnd()));
        tv_sender.setText(progressModel.getSendName());
        tv_main.setText(progressModel.getReceiveName());
        ll_root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserListActivity.toThisActivity(ProgressActivity.this, progressModelList);
            }
        });
    }

    @Override
    public int getItemCount() {
        return progressModels.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }
}
